//
//  WoundDesCellEditTwo.m
//  WSJWoundDesVC
//
//  Created by wsj2015 on 16/3/30.
//  Copyright © 2016年 wsj2015. All rights reserved.
//

#import "WoundDesCellEditTwo.h"
#import "WSJReadPlistTool.h"
@implementation WoundDesCellEditTwo

- (void)awakeFromNib {
    // Initialization code
    self.tf1.enabled = NO;
    self.tf2.enabled = NO;
    [self.selectBtn setImage:[UIImage imageNamed:@"evaluation_unselected"] forState:UIControlStateNormal];
    [self.selectBtn setImage:[UIImage imageNamed:@"evaluation_selected"] forState:UIControlStateSelected];
    self.tf1.delegate =self;
    self.tf2.delegate = self;
    self.tf1.keyboardType = UIKeyboardTypeNumberPad;
    self.tf2.keyboardType = UIKeyboardTypeNumberPad;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
   
    // Configure the view for the selected state
}
-(void)setModel:(WoundContentModel *)model{
    [super setModel:model];
//    self.contentLabel.text = model.content;
    NSArray *resultArr =[model.content componentsSeparatedByString:kKeySepcicalWord];
    if (resultArr.count==3) {
        self.label1.text = resultArr[0];
        self.label2.text = resultArr[1];
        self.label3.text = resultArr[2];
    }
    
    self.selectBtn.selected = model.isSelect;
    if (!model.isSelect &&model.readonly ==NO) {
        self.label1.textColor = [UIColor grayColor];
         self.label2.textColor = [UIColor grayColor];
         self.label3.textColor = [UIColor grayColor];
    }else{
        self.label1.textColor = [UIColor blackColor];
        self.label2.textColor = [UIColor blackColor];
        self.label3.textColor = [UIColor blackColor];
       
    }
    
    if (!model.isSelect) {
        self.tf1.text =nil;
        self.tf2.text =nil;
    }else{
        
        self.tf1.text =model.editStrO;
        self.tf2.text =model.editStrO;
    }
    
    
    
}
- (IBAction)selectAction:(UIButton *)sender {
    sender.selected = !sender.selected;
    if (self.model.readonly ==NO) {
        if (sender.selected ) {
            self.label1.textColor = [UIColor blackColor];
            self.label2.textColor = [UIColor blackColor];
            self.label3.textColor = [UIColor blackColor];
            self.tf1.enabled =YES;
            self.tf2.enabled =YES;
        }else{
            self.label1.textColor = [UIColor grayColor];
            self.label2.textColor = [UIColor grayColor];
            self.label3.textColor = [UIColor grayColor];
            self.tf1.enabled =NO;
            self.tf2.enabled =NO;
            self.tf1.text = nil;
            self.tf2.text = nil;
        }
    }
    
    if (self.btnBlock) {
        self.btnBlock(sender.selected);
    }

}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    
    NSMutableString *text = [NSMutableString stringWithString:textField.text];
    [text replaceCharactersInRange:range withString:string];
    
    if (text.length == 0) {
        return YES;
    }
    if ([string isEqualToString:@"."]) {
        return YES;
    }
    NSScanner* scan = [NSScanner scannerWithString:text];
    float val;

    return [scan scanFloat:&val] && [scan isAtEnd];
   
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    if (textField == self.tf1) {
        
    
        self.model.editStrO  =textField.text;
    }else if(textField == self.tf2){
       
        self.model.editStrT  = textField.text;
    }
    return YES;
}
@end
